class Solution:
    def reverseList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if not head or not head.next:
            return head
        Node = None
        while head:
            p = head
            head = head.next  #后面三步为反转
            p.next = Node
            Node = p
        return Node

#%%
class Solution:
    def reverseList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        node = None
        while head:
            tmp_h = head
            head = head.next
            tmp_h.next = node
            node = tmp_h